import request from '@/utils/request'

// 角色
export function fetchRoleList(query) {
  return request({
    url: '/backend/role/list',
    method: 'get',
    params: query
  })
}

// 角色用户
export function fetchRoteUserList(role) {
  return request({
    url: '/backend/role/user-list',
    method: 'get',
    params: {
      role: role
    }
  })
}
// 搜索用户
export function fetchSearchUser(query) {
  return request({
    url: '/backend/role/search-user',
    method: 'get',
    params: query
  })
}

// 授权用户
export function fetchAssignUser(role, uid) {
  return request({
    url: '/backend/role/assign-user',
    method: 'post',
    data: {
      uid: uid,
      role: role
    }
  })
}

// 删除授权用户
export function fetchRevokeUser(role, uid) {
  return request({
    url: '/backend/role/revoke-user',
    method: 'post',
    data: {
      uid: uid,
      role: role
    }
  })
}

export function fetchAssignPermission(role, data) {
  return request({
    url: '/backend/role/assign-permission',
    method: 'post',
    data: {
      permissions: data,
      role: role
    }
  })
}

export function fetchAssignMenu(role, data) {
  return request({
    url: '/backend/role/assign-menu',
    method: 'post',
    data: {
      menus: data,
      role: role
    }
  })
}

export function fetchCreateRole(data) {
  return request({
    url: '/backend/role/create',
    method: 'post',
    data: data
  })
}

export function fetchUpdateRole(data) {
  return request({
    url: '/backend/role/update',
    method: 'post',
    data: data
  })
}

export function fetchDeleteRole(name) {
  return request({
    url: '/backend/role/delete',
    method: 'post',
    data: {role: name}
  })
}
